Fix NameError in HuggingFaceGenerationAdapter.prepare_inputs_for_generation#136
Closed
whn09 wants to merge 1 commit intoaws-neuron:mainfrom
Closed
Fix NameError in HuggingFaceGenerationAdapter.prepare_inputs_for_generation#136whn09 wants to merge 1 commit intoaws-neuron:mainfrom
whn09 wants to merge 1 commit intoaws-neuron:mainfrom
Conversation
…ration prepare_inputs_for_generation builds model_inputs with `"tensor_capture_hook": tensor_capture_hook` but never extracts tensor_capture_hook from **kwargs (while input_capture_hook is extracted in the line directly above it). Any call path that reaches this method — including adapter.generate() — raises NameError. The fix is to extract tensor_capture_hook from kwargs, mirroring how input_capture_hook is handled. No other change is needed because NeuronBaseForImageToText.forward already accepts tensor_capture_hook as a keyword argument. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
HuggingFaceGenerationAdapter.prepare_inputs_for_generationbuildsmodel_inputswithbut never extracts
tensor_capture_hookfrom**kwargs, whileinput_capture_hookis extracted on the line immediately above it. Any call path that reaches this method — includingadapter.generate()on a model whoseforward()accepts atensor_capture_hookkwarg (e.g.NeuronBaseForImageToTextsubclasses) — raisesNameError: name 'tensor_capture_hook' is not defined.This PR adds the missing one-line extraction, mirroring how
input_capture_hookis handled.Reproduction
Any call to
adapter.generate(...)where the underlying model declarestensor_capture_hookin itsforwardsignature triggers the bug. Minimal example:Fix
src/neuronx_distributed_inference/utils/hf_adapter.py:input_capture_hook = kwargs.get("input_capture_hook", None) + tensor_capture_hook = kwargs.get("tensor_capture_hook", None)Behavior for callers that do not pass
tensor_capture_hookis unchanged (it staysNone, which is whatmodel_inputs["tensor_capture_hook"] = Nonealready means in the existing code).Testing
adapter.generate()on an image-to-text model no longer raisesNameError.**kwargswith aNonedefault, matching the pattern already used forinput_capture_hookandaccepted_indices.Compatibility
Related
Surfaced while refactoring #135 (Qwen2.5-Omni-7B contrib), whose Talker drives generation via
adapter.generate()and therefore hits this path. Once this fix lands, the workaround shim incontrib/models/Qwen2.5-Omni-7B/src/_upstream_compat.pycan be removed.By submitting this PR, I confirm that: